package com.briup.dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.briup.bean.Product;
import com.briup.bean.User;
import com.briup.dao.IreduceDao;

public class IreduceDaoImpl implements IreduceDao{
	private String driver="oracle.jdbc.driver.OracleDriver";
	private String url="jdbc:oracle:thin:@localhost:1521:XE";
	private String username="hon";
	private String password="this";
	@Override
	public void saveReduce(User user, Product product) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement ps=null;
		try {
			Class.forName(driver);
			conn=DriverManager.getConnection(url, username, password);
			String sql="insert into s_reduce values(my_seq.nextval,?,?,?)";
			ps=conn.prepareStatement(sql);
			System.out.println("有数据");
			ps.setLong(1, user.getId());
			ps.setLong(2, product.getId());
			ps.setDouble(3, product.getPrice());
			ps.execute();
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				if(ps!=null)ps.close();
				if(conn!=null)conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
